package zjl.base;

import zjl.graph.Path;

import java.util.List;

public class BizRequest implements Comparable<BizRequest> {
    private static int currId = 0;

    private int id = currId++;

    private NodeHost src;  // 起始端系统节点
    private NodeHost dest; // 目的端系统节点
    private int length;   // 业务数据长度 -- bit
    private int period;   // 业务运行周期 -- s(slot_length = 1s)
    private int deadline; // 业务发送时限 -- s(slot_length = 1s)

    // 临时中间数据
    private List<Path> kspPathList;
    private Path selectedPath;

    public BizRequest() {}

    public int getId() {
        return id;
    }

    public NodeHost getSrc() {
        return src;
    }

    public void setSrc(NodeHost src) {
        this.src = src;
    }

    public NodeHost getDest() {
        return dest;
    }

    public void setDest(NodeHost dest) {
        this.dest = dest;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getPeriod() {
        return period;
    }

    public void setPeriod(int period) {
        this.period = period;
    }

    public int getDeadline() {
        return deadline;
    }

    public void setDeadline(int deadline) {
        this.deadline = deadline;
    }

    public void setKspPathList(List<Path> paths) {
        this.kspPathList = paths;
    }

    public int getKspSize() {
        return this.kspPathList.size();
    }

    public Path getSelectedPath() {
        return selectedPath;
    }

    public void setSelectedPath(Path selectedPath) {
        this.selectedPath = selectedPath;
    }

    public Path getKspPath(int idx) {
        return this.kspPathList.get(idx);
    }

    @Override
    public int compareTo(BizRequest o) {
        if (this.period < o.period) {
            return 1;
        } else if (this.period == o.period) {
            if (this.length < o.length) {
                return 1;
            } else if (this.length == o.length) {
                if (this.deadline < o.deadline) {
                    return 1;
                } else if (this.deadline == o.deadline) {
                    return 0;
                }
            }
        }

        return -1;
    }

    @Override
    public String toString() {
        return "BizRequest{" +
                "src=" + src +
                ", dest=" + dest +
                ", length=" + length +
                ", period=" + period +
                ", deadline=" + deadline +
                '}';
    }

}
